package com.va.yahooweather.commons;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import org.apache.log4j.*;

public class DateUtil {

    private static final Logger log = Logger.getLogger(DateUtil.class);

    public static final SimpleDateFormat[] rfc822DateFormats = new SimpleDateFormat[]{
        new SimpleDateFormat("EEE, d MMM yy HH:mm:ss z", Locale.US),
        new SimpleDateFormat("EEE, d MMM yy HH:mm z", Locale.US),
        new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.US),
        new SimpleDateFormat("EEE, d MMM yyyy HH:mm z", Locale.US),
        new SimpleDateFormat("d MMM yy HH:mm z", Locale.US),
        new SimpleDateFormat("d MMM yy HH:mm:ss z", Locale.US),
        new SimpleDateFormat("d MMM yyyy HH:mm z", Locale.US),
        new SimpleDateFormat("d MMM yyyy HH:mm:ss z", Locale.US),
        //exception to RFC 822 format used by Yahoo "Thu, 22 Dec 2011 1:50 pm CET"
        new SimpleDateFormat("EEE, dd MMM yyyy hh:mm a z", Locale.US)
    };

    public static Date parseDate(String sDate) {
        for (SimpleDateFormat format : rfc822DateFormats) {
            try {
                return format.parse(sDate);
            } catch (Exception e) {
            }//skipping exception
        }

        log.info("Unknown date format " + sDate);
        return null;

    }
    
    public static boolean areEquals(Date date1, Date date2) {
        return date1.getTime() == date2.getTime();
    }
}
